package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.BusCbsxx;
import com.ruoyi.business.domain.vo.BusCbsxxSaveVO;
import com.ruoyi.business.mapper.BusCbsxxMapper;
import com.ruoyi.business.mapper.BusFyglMapper;
import com.ruoyi.business.mapper.BusZdgzMapper;
import com.ruoyi.business.service.IBusCbsxxService;
import com.ruoyi.business.utils.BusOperatorUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 承包商信息Service业务层处理
 *
 * @author yaowei
 * @date 2021-06-30
 */
@Service
public class BusCbsxxServiceImpl implements IBusCbsxxService {
    @Autowired
    private BusCbsxxMapper busCbsxxMapper;

    @Autowired
    private BusZdgzMapper busZdgzMapper;

    @Autowired
    private BusFyglMapper busFyglMapper;

    /**
     * 查询承包商信息
     *
     * @param id 承包商信息ID
     * @return 承包商信息
     */
    @Override
    public BusCbsxx selectBusCbsxxById(Long id) {
        return busCbsxxMapper.selectBusCbsxxById(id);
    }

    /**
     * 查询承包商信息列表
     *
     * @param busCbsxx 承包商信息
     * @return 承包商信息
     */
    @Override
    public List<BusCbsxx> selectBusCbsxxList(BusCbsxx busCbsxx) {
        return busCbsxxMapper.selectBusCbsxxList(busCbsxx);
    }

    /**
     * 新增承包商信息
     *
     * @param busCbsxxVo 承包商信息
     * @return 结果
     */
    @Override
    public int insertBusCbsxx(BusCbsxxSaveVO busCbsxxVo) {
        BusCbsxx cbsxx = BeanUtils.copyBean(busCbsxxVo, new BusCbsxx());
        BusOperatorUtils.setOperator(cbsxx);
        return busCbsxxMapper.insertBusCbsxx(cbsxx);
    }

    /**
     * 修改承包商信息
     *
     * @param busCbsxxVo 承包商信息
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateBusCbsxx(BusCbsxxSaveVO busCbsxxVo) {
        Long id = busCbsxxVo.getId();
        BusCbsxx cbsxx = busCbsxxMapper.selectBusCbsxxById(id);
        BeanUtils.copyBean(busCbsxxVo, cbsxx);
        BusOperatorUtils.setOperator(cbsxx);
        busZdgzMapper.updateCbsName(id, cbsxx.getCbsName());
        busFyglMapper.updateCbsName(id, cbsxx.getCbsName());
        return busCbsxxMapper.updateBusCbsxx(cbsxx);
    }

    /**
     * 批量删除承包商信息
     *
     * @param ids 需要删除的承包商信息ID
     * @return 结果
     */
    @Override
    public int deleteBusCbsxxByIds(Long[] ids) {
        return busCbsxxMapper.deleteBusCbsxxByIds(ids);
    }

    /**
     * 删除承包商信息信息
     *
     * @param id 承包商信息ID
     * @return 结果
     */
    @Override
    public int deleteBusCbsxxById(Long id) {

        return busCbsxxMapper.deleteBusCbsxxById(id);
    }

    /**
     * 统计在职人员数量
     *
     * @return
     */
    @Override
    public Long countAll() {
        return busCbsxxMapper.countAll();
    }
}
